using System;
using System.Data;
using System.Drawing;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
 

/// <summary>
/// Summary description for Class1
/// </summary> 
public class Common 
{
    string connectionString;
    public Common()
    {
         
    }
    public Common(string sqlConnectionString)
    {
        connectionString = sqlConnectionString;
    }
    public string RandomWord(int seed)
    {

        Random random = new Random(seed);
        int randomNumber = random.Next();
        return Convert.ToString(randomNumber, 16);
    }
    public int CheckResume(string userID)
    {
        int records = 0;
        SqlServerProvider cls = new
        SqlServerProvider(connectionString);
        cls.CommandText =
        "select  count(*) from vwJSResumes" +
         " where UserID=@UserID";
        cls.ParameterCollection =
        new string[1] { "@UserID" };
        cls.ValueCollection = new
        string[1] { userID };
        records =
        Convert.ToInt32(cls.ExecuteScalar());

         
        return records;
    }
    public DataSet GetDataSet(string selectQuery,
    string parameterName,
    string valueOfParameter)
    {
        SqlServerProvider sqlServerProvider
        = new SqlServerProvider();
        sqlServerProvider.ConnectionString
        = connectionString;
        sqlServerProvider.CommandText = selectQuery;
        sqlServerProvider.ParameterCollection =
        new string[1] { parameterName };
        sqlServerProvider.ValueCollection =
        new string[1] { valueOfParameter };
        sqlServerProvider.CommandType =
        CommandType.StoredProcedure;
        DataSet dataSet =
        sqlServerProvider.GetDataSet();
        return dataSet;
    }
    public DataTable GetDataTable(string selectQuery,
    string parameterName,
    string valueOfParameter)
    {
        SqlServerProvider sqlServerProvider
        = new SqlServerProvider();
        sqlServerProvider.ConnectionString
        = connectionString;
        sqlServerProvider.CommandText =
        selectQuery;
        sqlServerProvider.ParameterCollection =
        new string[1] { parameterName };
        sqlServerProvider.ValueCollection =
        new string[1] { valueOfParameter };
        sqlServerProvider.CommandType =
        CommandType.StoredProcedure;
        DataTable dataTable =
        sqlServerProvider.GetDataTable();
        return dataTable;
    }
    public DataTable GetDataTable(string selectQuery)
    {
        SqlServerProvider sqlServerProvider
        = new SqlServerProvider();
        sqlServerProvider.ConnectionString
        = connectionString;
        sqlServerProvider.CommandText = selectQuery;

        DataTable dataTable =
        sqlServerProvider.GetDataTable();
        return dataTable;
    }
     
    public DataSet GetDataSet(string selectQuery)
    {
        SqlServerProvider sqlServerProvider
        = new SqlServerProvider();
        sqlServerProvider.ConnectionString
        = connectionString;
        sqlServerProvider.CommandText = selectQuery;
        DataSet dataSet =
        sqlServerProvider.GetDataSet();
        return dataSet;
    }
    public string CreateScriptForPrint(string zoneName)
    {
        string str = 
        "<SCRIPT language='javascript'>\n";        
        str += " function openWindow" + 
        zoneName + "(obj,h,w)\n";
        str += "{\n";

        str += " var newWindow;";

        str += " if(screen.width){\n";
        str += " var winl = (screen.width-w)/2;\n";
        str += " var wint = (screen.height-h)/2;\n";
        str += " }else{winl = 0;wint =0;}\n";
        str += " if (winl < 0) winl = 0;\n";
        str += " if (wint < 0) wint = 0;\n";

        str += " var props = 'top='+wint+',"+
        "left='+winl+',scrollBars=yes,"+
        "resizable=yes,toolbar=no,"+
        "menubar=no,location=no,"+
        "directories=no,width='+w+'"+
        ",height='+h;\n";

        str += " newWindow = window.open(''"+
        ", 'Add_from_Src_to_Dest', props);\n";

        str += " newWindow.document.writeln('<html>')\n";
        str += " newWindow.document.writeln('<head>')\n";
        str += " newWindow.document.writeln('<Title>Print')\n";
        str += " newWindow.document.writeln('</Title>')\n";
        str += " newWindow.document.writeln('<link href=\"/css/style.css\" rel=\"stylesheet\"/>')\n";
        str += " newWindow.document.writeln('<link href=\"/css/newstyle.css\" rel=\"stylesheet\"/>')\n";
        str += " newWindow.document.writeln('</head>')\n";
        str += " newWindow.document.writeln('<body topmargin=\"0\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\">');\n";
        str += " newWindow.document.writeln('<form method=\"\" name =\"frm\">')\n";
        str += " newWindow.document.writeln('<table onclick=\"javascript:return false;\" border=0 width=100%><tr><td>');\n";
        str += " var strText = document.getElementById(obj).innerHTML;\n";
        
        str += " newWindow.document.writeln(strText);\n";
        str += " newWindow.document.writeln('</td></tr></table>');\n";
        str += " var strButton = \"<div align=right>"+
        "<input type=\\\"button\\\" name='btnPrint' "+
        "id='btnPrint' class='Button' value='Print'"+
        "  Onclick=\\\"document.getElementById('"+
        "btnPrint').style.display='none';window.print();"+
        "document.getElementById('btnPrint').style.display="+
        "'block';\\\"></div>\";\n";
        str += " newWindow.document.writeln(strButton);\n";
        str += " newWindow.document.writeln('</form>');\n";
        str += " newWindow.document.writeln('</body>');\n";
        str += " newWindow.document.writeln('</html>')\n";
        str += " newWindow.document.close();\n";
        str += "}\n";

        str += " String.prototype.replaceAll = "+
        "function(strTarget,strSubString)\n";
        str += " {\n";
        str += " var strReplaceAll = this;\n";
        str += " var intIndexOfMatch = "+
        "strReplaceAll.indexOf( strTarget );\n";
        str += " while (intIndexOfMatch != -1){\n";
        str += "  strReplaceAll = strReplaceAll.replace("+
        "strTarget, strSubString )\n";
        str += "  intIndexOfMatch = "+
        "strReplaceAll.indexOf( strTarget );}\n";
        str += " return( strReplaceAll );\n";
        str += " }\n";
        str += " \n";

        str += "</SCRIPT>\n";
        return str;
    }

    public void CheckJobExisting(GridView gridView, 
    int hyperLinkFieldIndex, 
    int checkFieldIndex)
    {

        foreach (GridViewRow gridViewRow in gridView.Rows)
        {

            HyperLink hyperLink = (HyperLink)
            gridViewRow.Cells[hyperLinkFieldIndex].Controls[0];

            if (gridViewRow.Cells[checkFieldIndex].Text == "Expiry"
             || gridViewRow.Cells[checkFieldIndex].Text == "Deleted")
            {
                hyperLink.NavigateUrl = "";
            }

        }

    }
    
}
